home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1998 July
/
EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso
/
earkit
/
news
/
thor
/
hd-install
/
thor.lha
/
rexx
/
BBSRead
/
SplitDigest.br
< prev
Wrap
Text File
|
1997-08-29
|
13KB
|
389 lines
/*
** $VER: SplitDigest.br 1.01 (20.5.97)
** by Eirik Nicolai Synnes
**
** See SortMail.guide for documentation
**
*/
options results
options failat 31
parse arg arguments
/*
** Initialize some variables
*/
version = subword(sourceline(2), 4, 1)
template = 'SYSTEM/A,CONFERENCE/A,MSGNO/A/N,DESTSYS/A,DESTCONF/A,REPLYADDR/K'
globals = 'args. data. head. text. newmsg. BBSREAD.LASTERROR myerr globals'
/*
** Find/open BBSREAD ARexx port
*/
if ~show('P', 'BBSREAD') then do
address(command)
'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
if exists('SYS:RexxC/WaitForPort') then 'SYS:RexxC/WaitForPort BBSREAD'
else 'WaitForPort BBSREAD'
if (rc = 5) then do; myerr = 'Couldn''t open BBSREAD''s ARexx port.'; rc = 30; signal error; end
if (rc ~= 0) then do; myerr = 'Could not find SYS:Rexxc/WaitForPort.'; rc = 30; signal error; end
end
/*
** Give template if arguments = '?' or empty
*/
if (arguments = '?') | (arguments = '') then do
say 'Usage: 'template
say 'SplitDigest.br is an external script for SortMail.'
exit(5)
end
address(bbsread)
'READARGS "'template'" 'args' CMDLINE 'arguments
if (rc ~= 0) then do
say BBSREAD.LASTERROR
say 'Template: 'template
say 'SplitDigest.br is an external script for SortMail.'
exit(5)
end
/*
** Utilize BBSRead's copyback buffer
*/
address(bbsread)
'BUFMODE COPYBACK'
/*
** Read message's header and text stems
*/
'READBRMESSAGE "'args.SYSTEM'" "'args.CONFERENCE'" 'args.MSGNO' HEADSTEM 'head' DATASTEM 'data' TEXTSTEM 'text
if rc ~= 0 then signal error
if symbol('text.TEXT.COUNT') = 'VAR' & text.TEXT.COUNT > 0 & symbol('text.PART.COUNT') = 'VAR' & text.PART.COUNT > 0 then do
myerr = 'Message contains both a text body and text parts.'; rc = 5; signal error
end
if symbol('text.PART.COUNT') = 'VAR' & text.PART.COUNT > 0 then do
do i = 1 to text.PART.COUNT
if (symbol('text.PART.'i'.TEXT.COUNT') = 'VAR' | symbol('text.PART.'i'.COMMENT.COUNT') = 'VAR' | symbol('text.PART.'i'.BINARY') = 'VAR') then do
myerr = 'MIME digest contains a non-text part.'; rc = 5; signal error
end
if symbol('text.PART.'i'.MSG.FROMNAME') ~= 'VAR' then do
if symbol('text.PART.'i'.MSG.PART.1.MSG.FROMNAME') = 'VAR' then text.PART.i.MSG.fromname = text.PART.i.MSG.PART.1.MSG.FROMNAME
else text.PART.i.MSG.fromname = head.FROMNAME
end
if symbol('text.PART.'i'.MSG.FROMADDR') ~= 'VAR' then do
if symbol('text.PART.'i'.MSG.PART.1.MSG.FROMADDR') = 'VAR' then text.PART.i.MSG.FROMADDR = text.PART.i.MSG.PART.1.MSG.FROMADDR
else text.PART.i.MSG.FROMADDR = head.FROMADDR
end
if symbol('text.PART.'i'.MSG.TONAME') ~= 'VAR' then do
if symbol('text.PART.'i'.MSG.PART.1.MSG.TONAME') = 'VAR' then text.PART.i.MSG.TONAME = text.PART.i.MSG.PART.1.MSG.TONAME
else text.PART.i.MSG.TONAME = head.TONAME
end
if symbol('text.PART.'i'.MSG.TOADDR') ~= 'VAR' then do
if symbol('text.PART.'i'.MSG.PART.1.MSG.TOADDR') = 'VAR' then text.PART.i.MSG.TOADDR = text.PART.i.MSG.PART.1.MSG.TOADDR
else text.PART.i.MSG.TOADDR = head.TOADDR
end
if symbol('text.PART.'i'.MSG.REFID') ~= 'VAR' then do
if symbol('text.PART.'i'.MSG.PART.1.MSG.REFID') = 'VAR' then text.PART.i.MSG.REFID = text.PART.i.MSG.PART.1.MSG.REFID
else text.PART.i.MSG.REFID = head.REFID
end
if symbol('text.PART.'i'.MSG.CREATIONDATE') ~= 'VAR' then do
if symbol('text.PART.'i'.MSG.PART.1.MSG.CREATIONDATE') = 'VAR' then text.PART.i.MSG.CREATIONDATE = text.PART.i.MSG.PART.1.MSG.CREATIONDATE
else text.PART.i.MSG.CREATIONDATE = head.CREATIONDATE
end
if symbol('text.PART.'i'.MSG.CREATIONDATETXT') ~= 'VAR' then do
if symbol('text.PART.'i'.MSG.PART.1.MSG.CREATIONDATETXT') = 'VAR' then text.PART.i.MSG.CREATIONDATETXT = text.PART.i.MSG.PART.1.MSG.CREATIONDATETXT
else text.PART.i.MSG.CREATIONDATETXT = head.CREATIONDATETXT
end
if symbol('text.PART.'i'.MSG.SUBJECT') ~= 'VAR' then do
if symbol('text.PART.'i'.MSG.PART.1.MSG.SUBJECT') = 'VAR' then text.PART.i.MSG.SUBJECT = text.PART.i.MSG.PART.1.MSG.SUBJECT
else text.PART.i.MSG.SUBJECT = head.SUBJECT
end
if symbol('args.REPLYADDR') ~= 'VAR' then do
if symbol('text.replyaddr') = 'VAR' then do
text.PART.i.MSG.replyaddr = text.replyaddr
if symbol('text.replyname') = 'VAR' then text.PART.i.MSG.replyname = text.replyname
end
else do
text.PART.i.MSG.replyaddr = head.fromaddr
if symbol('head.fromname') = 'VAR' then text.PART.i.MSG.replyname = head.fromname
end
end
else text.PART.i.MSG.replyaddr = args.REPLYADDR
text.PART.i.MSG.replyconf = args.CONFERENCE
call writemessage(SYSTEM '"'args.DESTSYS'"' CONFERENCE '"'args.DESTCONF'"' MSGSTEM value(text.PART.'i'.MSG))
end
end
else do
line = 1; parsed = 0
do forever
newmsg.text.count = 0
fromline = 0; subjline = 0; dateline = 0
do until (text.TEXT.line = '') & (fromline ~= 0)
select
when upper(subword(text.TEXT.line, 1, 1)) = "FROM:" then fromline = line
when upper(subword(text.TEXT.line, 1, 1)) = "SUBJECT:" then subjline = line
when upper(subword(text.TEXT.line, 1, 1)) = "DATE:" then dateline = line
when line > text.TEXT.count then do
if ~parsed then do
myerr = 'Unexpected end of message.'; rc = 5; signal error
end
else return(0)
end
otherwise nop
end
line = line + 1
end
/* Pick up date line and skip blank lines */
do forever
if line = text.TEXT.count then do
myerr = 'Failed to find start of first submessage''s text body.'; rc = 5; signal error
end
if upper(subword(text.TEXT.line, 1, 1)) = "DATE:" then dateline = line
else if text.TEXT.line ~= '' then break
line = line + 1
end
/* Search for 'End of message' line or the end of the digest */
newmsg.text.count = 0; msgline = 0; foundend = 0
do forever
notthisone = 0
if line = text.TEXT.count then do
myerr = 'Immature end of message.'; rc = 5; signal error
end
if (symbol('endsubmsg') ~= 'VAR') & (upper(subword(text.TEXT.line, 1, 1)) = "FROM:") then do
myerr = 'End of submessage not detected.'; rc = 5; signal error
end
if symbol('endsubmsg') ~= 'VAR' then do
if (left(text.TEXT.line, 1) = '-') & (length(text.TEXT.line) > 29) & (length(text.TEXT.line) = length(compress(text.TEXT.line))) & (text.TEXT.line = copies(left(text.TEXT.line, 1), length(text.TEXT.line))) then do
templine = line + 1
do until (foundend) | (notthisone) | (templine = text.TEXT.count)
if (text.TEXT.templine ~= '') then do
if (upper(subword(text.TEXT.templine, 1, 1)) = "FROM:") | (upper(subword(text.TEXT.templine, 1, 1)) = "DATE:") | (upper(subword(text.TEXT.templine, 1, 1)) = "SUBJECT:") | (upper(left(text.TEXT.templine, 9)) = 'MESSAGE #') then do
endsubmsg = text.TEXT.line; foundend = 1
end
else if ((templine + 7) <= text.TEXT.COUNT) then notthisone = 1; else foundend = 1
end
templine = templine + 1
end
end
end
else if compare(endsubmsg, text.TEXT.line) = 0 then foundend = 1
if foundend then break
msgline = msgline + 1; newmsg.text.msgline = text.text.line
newmsg.text.count = newmsg.text.count + 1
line = line + 1
end
/* Some magic to find name, address and subject */
newmsg.subject = "<no subject>"
newmsg.fromname = "Unknown"
newmsg.fromaddr = "<no address>"
from = strip(substr(text.TEXT.fromline, 6))
from = translate(from, '<>', '()')
i = pos("<", from)
if (i ~= 0) & (pos(">", from) > 0) then do
checkaddr = strip(substr(from, i, pos('>', from) - i), B, ' <>"')
if pos("@", checkaddr) = 0 then do
newmsg.fromname = checkaddr
newmsg.fromaddr = strip(delstr(from, i, pos('>', from) - i), B, ' >')
end
else do
newmsg.fromaddr = checkaddr
newmsg.fromname = strip(delstr(from, i, pos('>', from) - i), B, ' ">')
end
end
else do
if pos("@", from) = 0 then do
newmsg.fromname = strip(from, B, ' <>"')
end
else do
newmsg.fromaddr = strip(from, B, ' <>"')
end
end
if subjline ~= 0 then newmsg.subject = strip(subword(text.TEXT.subjline, 2))
if dateline ~= 0 then newmsg.creationdatetxt = strip(subword(text.TEXT.dateline, 2))
/* Removed msgid copying to avoid multiple messages with the same message id
if symbol('head.MSGID') ~= 'VAR' then newmsg.msgid = head.MSGID
*/
/* Find correct reply address */
if (args.REPLYADDR = '') | (right(args.REPLYADDR, 9) = 'REPLYADDR') then do
if symbol('TEXT.replyaddr') = 'VAR' then do
newmsg.replyaddr = TEXT.replyaddr
if symbol('TEXT.replyname') = 'VAR' then newmsg.replyname = TEXT.replyname
end
else do
newmsg.replyaddr = HEAD.fromaddr
if symbol('HEAD.fromname') = 'VAR' then newmsg.replyname = HEAD.fromname
end
end
else newmsg.replyaddr = args.REPLYADDR
newmsg.replyconf = args.CONFERENCE
call writemessage(SYSTEM '"'args.DESTSYS'"' CONFERENCE '"'args.DESTCONF'"' MSGSTEM newmsg)
drop newmsg.; parsed = 1
end
end
returned = 0; signal cleanup
/*
** Some error detection stuff
*/
error:
syntax:
returned = rc
select
when symbol('BBSREAD.LASTERROR') = 'VAR' then say 'Line 'sigl' returned 'returned': 'BBSREAD.LASTERROR
when symbol('myerr') = 'VAR' then say 'Line 'sigl' returned 'returned': 'myerr
otherwise say 'Line 'sigl' returned 'returned': 'errortext(returned)
end
break_c:
halt:
cleanup:
/*
** Turn off copyback buffer
*/
address(bbsread)
'BUFMODE ENDCOPYBACK'
exit(returned)
/****************************************************************************
************************** Write message to database **************************
****************************************************************************/
writemessage: interpret 'procedure expose 'globals
parse arg wmarguments
/*
** Initialize arguments and parse them
*/
wmtemplate = 'SYSTEM/A,CONFERENCE/A,MSGSTEM/A,DONTMARKMESSAGE/S,REPLIED/S,PRIVATE/S,KEEP/S,READ/S,URGENT/S,IMPORTANT/S,CONFIDENTIAL/S,HAZELEVEL/K/N'
CDB_MARK_OWN_MSGS = 22 /* Also mark messages from user when adding messages. */
CDF_NOT_ON_BBS = '00008000'x /* This conference is not on the bbs. */
CDNT_MAILFOLDER = 3 /* This conference is a virtual mail folder */
wmargs.DONTMARKMESSAGE = 0; wmargs.PRIVATE = 0; wmargs.READ = 0; wmargs.URGENT = 0
wmargs.IMPORTANT = 0; wmargs.CONFIDENTIAL = 0; wmargs.KEEP = 0; wmargs.REPLIED = 0
wmargs.HAZELEVEL = 0
address(bbsread)
'READARGS 'wmtemplate wmargs' CMDLINE 'wmarguments
if rc ~= 0 then signal error
/*
** See if the conference the msg will be written to exists
*/
'GETCONFLIST BBSNAME "'wmargs.SYSTEM'" STEM 'conflist
if rc ~= 0 then signal error
conflist.system = wmargs.SYSTEM
do n = 1 to conflist.COUNT + 1 while upper(wmargs.CONFERENCE) ~= upper(conflist.n)
if n = conflist.COUNT + 1 then do
/* Create the new conference */
'CONFIGCONF "'wmargs.SYSTEM'" "'wmargs.CONFERENCE'" SET 'c2x(CDF_NOT_ON_BBS)' CONFNETTYPE 'CDNT_MAILFOLDER
if (rc ~= 0) then signal error
conflist.n = toconf
conflist.COUNT = conflist.COUNT + 1
end
end
/*
** If Show own messages isn't activated in conference mark then don't
** mark message as unread.
*/
'GETCONFDATA "'wmargs.SYSTEM'" "'wmargs.CONFERENCE'" STEM 'confdata
if (rc ~= 0) then signal error
if (confdata.CONFTYPE ~= CDNT_MAILFOLDER) then do
'CONFIGCONF "'wmargs.SYSTEM'" "'wmargs.CONFERENCE'" SET 'c2x(CDF_NOT_ON_BBS)' CONFNETTYPE 'CDNT_MAILFOLDER
if (rc ~= 0) then signal error
end
/*
Need data. and bbsdata.
if ~bittst(confdata.FLAGS, CDB_MARK_OWN_MSGS) & (value(wmargs.msgstem'.fromaddr') = bbsdata.EMAILADDR) then wmargs.DONTMARKMESSAGE = 1
*/
/*
** Set the selected message flags
*/
writeflags = ''
if wmargs.DONTMARKMESSAGE then writeflags = writeflags'DONTMARKMESSAGE '
if wmargs.PRIVATE then writeflags = writeflags'PRIVATE '
if wmargs.READ then writeflags = writeflags'READ '
if wmargs.URGENT then writeflags = writeflags'URGENT '
if wmargs.IMPORTANT then writeflags = writeflags'IMPORTANT '
if wmargs.CONFIDENTIAL then writeflags = writeflags'CONFIDENTIAL '
updateflags = ''
if wmargs.KEEP then updateflags = updateflags'SETKEEP '
if wmargs.REPLIED then updateflags = updateflags'SETREPLIED '
if wmargs.HAZELEVEL > 0 then updateflags = updateflags'HAZELEVEL 'wmargs.HAZELEVEL' '
/*
** Write the message
*/
address(bbsread)
'WRITEBRMESSAGE "'wmargs.SYSTEM'" "'wmargs.CONFERENCE'" STEM 'wmargs.MSGSTEM
if rc ~= 0 then signal error
msgnr = result
/*
** Give the new message it's flags
*/
if updateflags ~= '' then do
'UPDATEBRMESSAGE "'wmargs.SYSTEM'" "'wmargs.CONFERENCE'" 'msgnr updateflags
if rc ~= 0 then signal error
end
return(0)